*Creating the variable measuring ideological self placement
gen ideo=q5

*Creating the legitimacy index
gen clegit1 = q19
gen clegit2 = q20
gen clegit3 = q21
gen clegit4 = q22
gen clegit3rev = clegit3
recode clegit3rev 1=5 2=4 4=2 5=1
gen clegit4rev = clegit4
recode clegit4rev 1=5 2=4 4=2 5=1
 
gen clegittot = clegit1+clegit2+clegit3rev+clegit4rev
gen clegit01 = (clegittot-4)/16

*Citizenship variable
gen citizen = q50

*Creating the acceptance index
gen accept1 = q37
recode accept1 2=-1
gen acpstr1 = q38
replace acpstr1 = q39 if q38==.

recode accept1 -1=0 if acpstr1==4
recode accept1 1=2 if acpstr1==3
recode accept1 1=3 -1=-2 if acpstr==2
recode accept1 1=4 -1=-3 if acpstr==1

gen accept2 = q40
replace accept2 = q41 if q40==.

gen accept3 = q42

gen acp1 = (accept1+3)/7
gen acp2 = (accept2-1)/6
gen acp3 = (accept3-1)/3

gen acpshort01 = (acp1+acp2+acp3)/3

*Creating the specific support index
gen ideodiff = q28
recode ideodiff 3=0 4=1 5=2 2=1 1=2

gen scjob = q32
recode scjob 1=4 2=3 3=2 4=1

recode ideodiff 0=2 2=0
gen ideodiff01 = ideodiff/2
gen scjob01 = (scjob-1)/3
gen output01 = (ideodiff01+scjob01)/2

*Creating Supreme Court Favorability Variable
gen scfavor = q31
recode scfavor -99=.

*Creating rule of law index
gen rlaw1 = q3
gen rlaw2 = q4
gen rlaw = rlaw1+rlaw2
gen rlaw01 = (rlaw-2)/8

*Creating election fairness index
gen elect1 = q1
gen elect2 = q2
gen electtot = q2-q1
gen elect01 = (electtot+4)/8


*Creating court awareness index
gen caware1 = q10
gen caware2 = q13

gen revcaware1 = caware1
recode revcaware1 1=4 2=3 3=2 4=1
replace revcaware1 = (revcaware1-1)/3
gen revcaware2 = caware2
recode revcaware2 1=6 2=5 3=4 4=3 5=2 6=1
replace revcaware2 = (revcaware2-1)/5
gen caware01 = (revcaware1+revcaware2)/2

*Creating the two attention-check variables
gen check1 = 0
recode check1 0=1 if q65_3==1&q65_5==1

gen check2 = q67
recode check2 1/5=0 6=1

*variable measuring whether someone was born in America
gen birth= q51

*variable measuring whether someone had heard about the topic of this case
gen caseknow = q200
recode caseknow -99=.

*variable assigning race
gen race = q91

*recoding decision-perception variables
gen cdec1 = q23
gen cdec2 = q24
gen cdec3 = q25
gen cdec4 = q26
gen cdec5 = q27

recode cdec2 1=5 2=4 4=2 5=1
recode cdec4 1=5 2=4 4=2 5=1
recode cdec5 1=5 2=4 4=2 5=1

*Creation of knowledge index
gen know1 = q7
recode know1 1/2=0 3=1 4=0

gen know2 = q8 
recode know2 1=0 2=1 3/max=0

gen know3 = q9
recode know3 1/5=0 6=1 7/max=0

gen knowtot = know1+know2+know3
gen know01 = knowtot/3


*Creating variables measuring pre- and post-decision positions on juvenile life sentence issue
gen preiss = q15

gen strpre = q16
replace strpre = q17 if q16==.
replace strpre = abs(strpre-5)
gen strpre01 = abs(strpre-1)/3

recode preiss 2=-1
replace preiss = preiss*strpre
recode preiss -4=-3 -3=-2 -2=-1 -1=0

gen postiss = q43

gen poststr = q57
replace poststr = q58 if q57==.
replace poststr = abs(poststr-5)

recode postiss 2=-1
replace postiss = postiss*poststr
recode postiss -4=-3 -3=-2 -2=-1 -1=0

*creating of the issue position change variable
gen isschange = postiss-preiss if preiss>0
replace isschange = -(postiss-preiss) if preiss<1
replace isschange = -isschange

*Creation of variable identifying the ideological direction of the court decision - 1= conservative decision, 0=liberal decision
gen decdirect = q15
recode decdirect 2=0
gen libdecision = q15
recode libdecision 2=1 1=0

*Creation of variable measuring the importance of the issue
gen imp = q18
recode imp 1=4 2=3 3=2 4=1
gen imp01 = (imp-1)/3

*Creation of gender variable
gen female = q49
recode female 1=0 2=1

*Creation of education and age variable
gen educ = q89-1
gen educ01 = educ/4
gen age10 = q52/10

*Creation of race indicator variables for each category
gen black = q91
recode black 1=0 2=0 3=1 4=0 5=0 6=0 7=0

gen hispanic = q91
recode hispanic 1=0 2=1 3=0 4=0 5=0 6=0 7=0

gen otherrace = q91
recode otherrace 1=0 2=0 3=0 4=1 5=1 6=1 7=1

*Transforming supreme court favorability and ideological self-placement into a 0 to 1 scale
gen favor01 = scfavor/100
gen ideo01 = (ideo-1)/6

*Creation of variable measuring whether a person's issue position on the juvenile life sentence changed directions
gen issswitch = 0
recode issswitch 0=1 if q15~=q43
recode issswitch 0=. 1=. if q15==.|q43==.

*Creation of decisional ideological conflict variable
gen ideoconflict = ideo
replace ideoconflict = -ideo+8 if libdecision==0
gen ideoconflict01 = (ideoconflict-1)/6
replace ideoconflict01 = abs(ideoconflict01-1)

*Creation of four-level issue position change variable
gen isschange4 = isschange
recode isschange4 2/5=2

*Mean centerining all variables
gen output01mean = output01 - .6642157
gen clegit01mean = clegit01 -  .6476716
gen rlaw01mean = rlaw01 - .5955882 
gen know01mean = know01 - .6535948
gen imp01mean = imp01-.3627451
gen caware01mean = caware01 - .627451
gen libdecisionmean = libdecision-.5098039
gen strpre01mean = strpre01-.5849673 
gen educ01mean = educ01-.629902 
gen ideo01mean = ideo01 - .4362745
gen femalemean = female - .5098039
gen blackmean = black - .0784314
gen hispanicmean = hispanic - .0686275
gen otherracemean = otherrace -  .0686275
gen isschangemean = isschange- .4901961 
gen ideoconflict01mean = ideoconflict01- .625817


*Creating variables with varying 0 points to use in models below calculating predicted values
gen output33 = output01- .3333333
gen output42 = output01- .4166667 
gen output5 = output01- .5 
gen output58 = output01- .5833334 
gen output66 = output01- .6666667
gen output75 = output01- .75 
gen output83 = output01- .8333334
gen outputrev = output01-1

gen clegit31 = clegit01-.3125
gen clegit37 = clegit01-.375 
gen clegit5 = clegit01-.5
gen clegit62 = clegit01- .625
gen clegit75 = clegit01- .75 
gen clegit87 = clegit01- .875
gen clegitrev= clegit01- 1

*models for columns 1 and 2 of table 1
regress isschange output01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1
regress acpshort01 output01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1

*model for column 1 of Appendix table 1
oprobit isschange4 output01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1

*alpha for legitimacy scale
alpha clegit1 clegit2 clegit3 clegit4 if check1==1&check2==1&citizen==1

*correllation between two specific support items
pwcorr ideodiff01 scjob01 if check1==1&check2==1&citizen==1, sig

*correllation between legitimacy perceptions and specific support
pwcorr clegit01 output01 if check1==1&check2==1&citizen==1, sig

*alpha for acceptance scale
alpha acp1 acp2 acp3 if check1==1&check2==1&citizen==1

*correlation between acceptance and issue position change
pwcorr acpshort01 isschange if check1==1&check2==1&citizen==1, sig

*calculating the distribution of the issue position change variable
tab isschange if check1==1&check2==1&citizen==1

*calculating the percentage of people who switched the direction of their position on the juvenile life sentence
tab issswitch if check1==1&check2==1&citizen==1


*The models below were used to calculate the predicted values of issue position change and the confidence intervals used in the middle panel of Figure 1. The constant in the models
*below is the predicted value of issue position change when all other varibles are held at zero. By mean-centering every other variable and changing the coding of the output01 variable,
*the constant and its associated confidence intervals can be calculated for various points along the specific support variable.

regress isschange output01  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output33  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output42  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output5  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output58  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output66  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output75  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange output83  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress isschange outputrev  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1


*The models below were used to calculate the predicted values acceptance and the confidence intervals used in the data analysis section. The constant in the models
*below is the predicted value of acceptance when all other varibles are held at zero. By mean-centering every other variable and changing the coding of the output01 variable,
*the constant and its associated confidence intervals can be calculated for various points along the specific support variable.

regress acpshort01 output01  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output33  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output42  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output5  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output58  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output66  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output75  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output83  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 outputrev  clegit01mean rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1


regress acpshort01 output01mean  clegit31 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegit37 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegit5 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegit62 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegit75 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegit87 rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1
regress acpshort01 output01mean  clegitrev rlaw01mean  know01mean  imp01mean  caware01mean libdecisionmean strpre01mean educ01mean ideoconflict01mean femalemean blackmean hispanicmean otherracemean if check1==1&check2==1&citizen==1

*model from footnote 5 in which the issue position change variable is recoded into a four-level ordinal variable
oprobit isschange4 output01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1

*model from footnote 8 in which the issue position change variable is added as an independent variable in the acceptance model
regress acpshort01 isschange output01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1

*models from footnote 9 discussing when the individual component of specific support replaces the specific support index 
regress isschange ideodiff01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1
regress isschange scjob01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1
regress acpshort01 ideodiff01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1
regress acpshort01 scjob01  clegit01 rlaw01  know01  imp01  caware01 libdecision strpre01 educ01 ideoconflict01 female black hispanic otherrace if check1==1&check2==1&citizen==1

